home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1823 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  33 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.sprintlink.net!news1!juggler
  3. From: juggler@iquest.net (Phil Paxton)
  4. Subject: Re: Shuffle
  5. X-Nntp-Posting-Host: dorite.iquest.net
  6. Message-ID: <juggler.821846324@iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Internet, Inc.
  9. X-Newsreader: NN version 6.5.0 #9 (NOV)
  10. References: <at-1601961212280001@sm1.psy.soton.ac.uk>
  11. Date: Wed, 17 Jan 1996 02:38:44 GMT
  12.  
  13. at@neuro.psy.soton.ac.uk (Adriaan Tijsseling) writes:
  14.  
  15. >For my neural network simulator I need a piece of code which shuffles
  16. >a set of n patterns in a random way. I.e. a set of 4 patterns would
  17. >then be shuffled such that I have a set of m orders of these patterns:
  18.  
  19. >1  2  3  4
  20. >4  3  1  2
  21. >2  1  3  4
  22.  
  23. Isn't the standard shuffling algorithm to order the list, then loop 
  24. backward from the last object to the first.  For each object, generate a 
  25. random # in the range of 0:n, then swap the objects at the generated 
  26. random # and the current index.  By the time you reach the first object, 
  27. the list will be randomized.
  28.  
  29.  
  30. --
  31.  ------------------------------------
  32.  Phil Paxton :: Fishers, Indiana, USA
  33.